/*
 * @Description:
 * @Author: maozhixin
 * @Date: 2022-01-21 11:18:10
 * @LastEditors: maozhixin
 * @LastEditTime: 2022-01-25 08:51:25
 */
export const readWriteType = {
  '1': '只读',
  '2': '读写',
};

export const valueType = {
  '1': 'int32/64/float/doubla',
  '2': 'string（字符串）',
  '3': 'bool（布尔）',
  '4': 'enum（枚举）',
};

export const changeArr = (obj: any) => {
  const arr: { name: string; value: any }[] = [];
  Object.keys(obj).forEach((key) => {
    arr.push({
      name: obj[key],
      value: key,
    });
  });
  return arr;
};

export const valueTypeDetail = (detail: any, unitMap: any) => {
  if (detail.type == 1) {
    return (
      <div>
        <div>
          定义取值范围：{detail?.attributeValue?.min} ~ {detail?.attributeValue?.max}
        </div>
        <div>步长：{detail?.attributeValue?.walkLength}</div>
        <div>
          单位：
          {detail?.attributeValue?.unitId && unitMap[String(detail?.attributeValue?.unitId)].symbol}
        </div>
      </div>
    );
  } else if (detail.type == 2) {
    return <div>数据长度：{detail?.attributeValue?.stringResult}</div>;
  } else if (detail.type == 3) {
    return (
      <div>
        {detail?.attributeValue?.booleanEnums.map((item: any) => (
          <div key={item.enumKey}>
            {item.enumKey}：{item.enumDesc}
          </div>
        ))}
      </div>
    );
  } else if (detail.type == 4) {
    return (
      <div>
        {detail?.attributeValue?.enums.map((item: any) => (
          <div key={item.enumKey}>
            枚举值：{item.enumKey}；参数描述：{item.enumDesc}
          </div>
        ))}
      </div>
    );
  }
  return null;
};
